import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'full_screen_image_viewer.dart';

class ImageGrid extends StatelessWidget {
  final List<String> images;

  const ImageGrid({Key? key, required this.images}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GridView.count(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      crossAxisCount: 3,
      mainAxisSpacing: 4.0,
      crossAxisSpacing: 4.0,
      children: List.generate(images.length, (index) {
        return GestureDetector(
          onTap: () {
            Get.to(() => FullScreenImageViewer(
              images: images,
              initialIndex: index,
            ));
          },
          child: Image.network(
            images[index],
            fit: BoxFit.cover,
            errorBuilder: (context, error, stackTrace) {
              return Container(
                color: Colors.grey[300],
                child: const Center(
                  child: Icon(Icons.broken_image, color: Colors.grey),
                ),
              );
            },
            loadingBuilder: (context, child, loadingProgress) {
              if (loadingProgress == null) return child;
              return Container(
                color: Colors.grey[200],
                child: const Center(
                  child: CircularProgressIndicator(),
                ),
              );
            },
          ),
        );
      }),
    );
  }
}